"""
Author : ZhengShiQi
dateTime: 2025/9/11 13:57
FileName: main.py
description: 挂载路由并配置数据库连接
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from app.api.router import api_router
from app.models.database import Base, engine

# 创建数据库表（首次运行时）
Base.metadata.create_all(bind=engine)

app = FastAPI(title="API模拟系统")

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许所有源，生产环境建议指定具体域名
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(api_router)

@app.get("/health")
def health_check():
    return {"status": "healthy"}
